//
//  MeService.m
//  HxgProject
//
//  Created by hxg on 2018/3/27.
//  Copyright © 2018年 XMYY-19. All rights reserved.
//

#import "MeService.h"
#import "NetworkManager.h"
#import "ApplyInfo.h"

@implementation MeService

- (void)getPackageDetailWithCallBack:(void(^)(NSMutableArray *returnArr)) callBack
{
    NetworkManager *man = [NetworkManager sharedNetworkManager];
    NSString *urlInfo = [NSString stringWithFormat:@"%@",@"http://47.104.139.178:8080/demo/paymentDetail/GetPackageDetail"];
    //2.封装参数
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"phone"] = [[NSUserDefaults standardUserDefaults] objectForKey:kPhoneNum];
    
    [man getURL:urlInfo parameters:params success:^(id responseObject) {
        NSLog(@"responseObject:%@",responseObject);
        
        NSMutableArray *allApplyInfos = [[NSMutableArray alloc] init];
        
        NSArray *arr = [responseObject objectForKey:@"paymentDetail"];
        if ([responseObject objectForKey:@"paymentDetail"] != [NSNull null]
            && nil != arr
            && 0 != arr.count
            )
        {
            for (NSDictionary *dic in arr)
            {
                if (![dic[@"state"] isKindOfClass:[NSNull class]])
                {
                    ApplyInfo *applyInfo = [[ApplyInfo alloc] init];
                    
                    if (![dic[@"period"] isKindOfClass:[NSNull class]])
                    {
                        applyInfo.applyCycle = dic[@"period"];
                    }
                    
                    if (![dic[@"applyTime"] isKindOfClass:[NSNull class]])
                    {
                        applyInfo.applyTime = dic[@"applyTime"];
                    }
                    
                    if (![dic[@"state"] isKindOfClass:[NSNull class]])
                    {
                        applyInfo.curState = dic[@"state"];
                    }
                    
                    if (![dic[@"packages"] isKindOfClass:[NSNull class]])
                    {
                        applyInfo.applyNum = dic[@"packages"];
                    }
                    
                    [allApplyInfos addObject:applyInfo];
                }
            }
        }
        
        callBack(allApplyInfos);
    } failure:^(NSError *error, ParamtersJudgeCode judgeCode) {
        NSLog(@"judgeCode===>%lu",(unsigned long)judgeCode);
        callBack(nil);
    }];
}


@end
